package codetop.dfs;



import codetop.TreeNode;

import java.util.*;

public class Code199 {
    public List<Integer> rightSideView(TreeNode root) {
        List<Integer>list=new ArrayList<>();
        Queue<TreeNode>queue=new LinkedList<>();
        queue.offer(root);
        while (!queue.isEmpty()){
            int size=queue.size();
            for (int i = 0; i < size; i++) {
                TreeNode node=queue.poll();
                if (node.left!=null)queue.offer(node.left);
                if (node.right!=null)queue.offer(node.right);
                if (i==size-1){
                    list.add(node.val);
                }
            }
        }
        return list;
    }
}
